package com.ym.pms.controller;

import com.ym.pms.annotation.CurrentUser;
import com.ym.pms.model.SysUser;
import com.ym.pms.service.IMailService;
import com.ym.pms.service.SysUserService;
import com.ym.pms.utils.JSONResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @Author: xybh
 * @Description:
 * @Date: Created in 2:25 2020/12/24
 * @Modified:
 */
@RestController
public class AdminController {

    @Autowired
    private SysUserService sysUserService;

    @Autowired
    private IMailService mailService;

    @PreAuthorize(value = "hasRole('ADMIN')")
    @RequestMapping("/userList")
    public JSONResult userList(@CurrentUser SysUser user) {
        List<SysUser> list = sysUserService.list();
        return JSONResult.ok(list.toString());
    }

    @PreAuthorize(value = "hasRole('BASIC')")
    @RequestMapping("/userList2")
    public JSONResult userList2(@CurrentUser SysUser user) {
        List<SysUser> list = sysUserService.list();
        return JSONResult.ok(list.toString());
    }

    @GetMapping("/confirm")
    public JSONResult confirm() {
        String to = "812964158@qq.com";
        boolean cf = false;
        String username = "澈力格尔";
        String requestId = "1";
        String subject = "你的租房申请已被" + (cf ? "通过" : "拒绝");
        mailService.sendConfirmMessage(to, subject, username,new Date(), requestId, cf);
        return JSONResult.ok();
    }

}
